const {
  MarketingModel
} = require('../../../../utils/marketing-model.js')
var marketingModel = new MarketingModel()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activityId: '',
    isPrizeRecord: false,
    nextRoundLotteryDate: null, //下一轮开始时间
    ticketList: [], //券列表
    currentRecord: [], //本期中奖券
    historyRecord: [], //历史中奖券
    preRoundLotteryDate: null, //上一期的开奖时间
    loadingFlag: null, //是否正在开奖: 0：否 1：是
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      activityId: options.activityCardId
    }, function () {
      this.getActivityInfo()
    })
  },

  /**
   * 活动详情
   */
  getActivityInfo: function () {
    wx.showLoading({
      title: '加载中',
      mask: true
    });
    var param = {};
    param.merchantId = wx.getStorageSync('merchantId'); //商户ID
    param.activityVerificationId = ''; //核销ID
    param.activityCardType = 2; //活动类型：1：集卡活动一期 2：全国活动 3：达人机活动
    param.activityCardId = this.data.activityId; //活动id
    marketingModel.verificationGet(param).then(data => {
      let nextRoundTime = data.nextRoundLotteryDate ? data.nextRoundLotteryDate.split(' ') : null
      let atime = data.nextRoundLotteryDate ? nextRoundTime[0].split('-') : null
      this.setData({
        nextRoundLotteryDate: data.nextRoundLotteryDate ? `${atime[0]}年${atime[1]}月${atime[2]}日` + `${nextRoundTime[1]}` : null,
        ticketList: data.ticketList || [], //券列表
        currentRecord: data.currentRecord || [], //本期中奖券
        historyRecord: data.historyRecord || [], //历史中奖券
        preRoundLotteryDate: data.preRoundLotteryDate || null, //上一期的开奖时间
        loadingFlag: data.loadingFlag || null //是否正在开奖: 0：否 1：是
      })
      wx.setNavigationBarTitle({
        title: data.activityName || ""
      })
    }).catch(err => {
      wx.showToast({
        title: `${err.error}`,
        icon: 'none',
        duration: 2000
      })
    })
  },

  /**
   * 查看历史获奖记录
   */
  prizeRecord: function () {
    this.setData({
      isPrizeRecord: !this.data.isPrizeRecord
    })
  }
})